package org.fastsyncer.connector.sql;

import org.fastsyncer.connector.config.DatabaseConfig;
import org.fastsyncer.connector.config.SqlConfig;
import org.fastsyncer.connector.constant.DatabaseConstant;
import org.fastsyncer.connector.database.AbstractDatabaseConnector;

public final class DQLMysqlConnector extends AbstractDatabaseConnector {

    @Override
    public SqlConfig getSqlConfig(DatabaseConfig config, String table, String queryFilter) {
        // SELECT * FROM USER WHERE ID = '123'
        String sql = config.getSql();
        // 查询元信息
        // SELECT * FROM USER LIMIT 0
        // SELECT * FROM USER WHERE ID = '123' LIMIT 0
        String metaSql = new StringBuilder().append(sql).append(DatabaseConstant.MYSQL_PAGE_SQL_NULL).toString();
        return new SqlConfig(metaSql, sql);
    }

    @Override
    public String getPageSql(DatabaseConfig config, String table, String sql) {
        // Mysql 分页查询
        return sql + DatabaseConstant.MYSQL_PAGE_SQL;
    }

}
